from rest_framework import serializers

from six_it.models import Recruit, Enterprise


class ThirdqiyeSerializer(serializers.ModelSerializer):
    '''5.企业第二层序列化器类'''

    class Meta:
        model = Recruit
        fields = ["id"]


class SecondzhaopinSerializer(serializers.ModelSerializer):
    '''4.招聘第二层序列化器类'''
    recruits = ThirdqiyeSerializer(many=True)

    class Meta:
        model = Enterprise
        fields = ["id", "name", "labels", "logo", "summary", 'recruits']


class SecondqiyeSerializer(serializers.ModelSerializer):
    '''3.企业第二层序列化器类'''

    enterprise = SecondzhaopinSerializer()

    class Meta:
        model = Recruit
        fields = ["id", "jobname", "salary", "condition", "education", "type", "city", "createtime", "labels",
                  "enterprise"]


#
class FirstzhaopinSerializer(serializers.ModelSerializer):
    '''2.招聘第一层序列化器类'''

    recruits = SecondqiyeSerializer(many=True)

    class Meta:
        model = Enterprise
        fields = ["id", "name", "summary", "content", "city", "address", "labels", "coordinate", "logo", "url",
                  "visits", 'recruits']


class FirstqiyeSerializer(serializers.ModelSerializer):
    '''1.企业第一层序列化器类'''
    enterprise = FirstzhaopinSerializer()

    class Meta:
        model = Recruit
        fields = ["id", "jobname", "salary", "condition", "education", "type", "city", "address", "state", "labels",
                  "detailcontent", "detailrequire", "visits", "createtime", "enterprise", "users"]
